
<!DOCTYPE html>
<html lang="zh-cn">
    <head>
        <meta charset="utf-8">
        <title>浏览页面</title>
        <link rel="stylesheet" href="/app/admin/component/pear/css/pear.css" />
        <link rel="stylesheet" href="/app/admin/admin/css/reset.css" />
        <style type="text/css">
            <!--.layui-table-cell {
                height: auto!important;
            } -->
        </style>
    </head>
    <body class="pear-container">
    
        <!-- 顶部查询表单 -->

        <!-- 数据表格 -->
        <div class="layui-card">
            <blockquote class="layui-elem-quote">
                <div>当新增了语种之后，需要手动修改 /config/translation.php 文件中的 fallback_locale 参数</div>
                <div>'fallback_locale' => [{$data}],</div>
            </blockquote>
            <div class="layui-card-body">
                <table id="data-table" lay-filter="data-table"></table>
            </div>
        </div>

        <!-- 表格顶部工具栏 -->
        <script type="text/html" id="table-toolbar">
            <button class="pear-btn pear-btn-primary pear-btn-md" lay-event="add" permission="admin.app.utillang.insert">
                <i class="layui-icon layui-icon-add-1"></i>新增
            </button>
<!--            <button class="pear-btn pear-btn-primary pear-btn-md" lay-event="generate" >-->
<!--                生成语言包数据-->
<!--            </button>-->
<!--            <button class="pear-btn pear-btn-danger pear-btn-md" lay-event="batchRemove" permission="admin.app.utillang.delete">-->
<!--                <i class="layui-icon layui-icon-delete"></i>删除-->
<!--            </button>-->
        </script>

        <!-- 表格行工具栏 -->
        <script type="text/html" id="table-bar">
            <button class="pear-btn pear-btn-xs tool-btn" lay-event="edit" permission="admin.app.utillang.update">编辑</button>
            <!-- data-url="/admin/utils/util-lang-detail/index?lang_id={{d.id}}" -->
            <button class="pear-btn pear-btn-xs tool-btn tab-click"  lay-event="translate"  data-title="语言包 - {{d.name}}">翻译</button>
            <button class="pear-btn pear-btn-xs tool-btn" lay-event="remove" permission="admin.app.utillang.delete">删除</button>
        </script>

        <script src="/app/admin/component/layui/layui.js?v=2.8.12"></script>
        <script src="/app/admin/component/pear/pear.js"></script>
        <script src="/app/admin/admin/js/permission.js"></script>
        <script src="/app/admin/admin/js/common.js"></script>
        <script src="/app/admin/admin/js/layuiAdmin.js"></script>
        
        <script>

            // 相关常量
            const PRIMARY_KEY = "id";
            const SELECT_API = "/admin/utils/util-lang/select";
            const UPDATE_API = "/admin/utils/util-lang/update";
            const DELETE_API = "/admin/utils/util-lang/delete";
            const INSERT_URL = "/admin/utils/util-lang/insert";

            
            // 字段 创建时间 created_at
            layui.use(["laydate"], function() {
                layui.laydate.render({
                    elem: "#created_at",
                    range: ["#created_at-date-start", "#created_at-date-end"],
                    placeholder: "请输入创建时间",
                    type: "datetime",
                });
            })
            
            // 表格渲染
            layui.use(["table", "form", "common", "popup", "util","soulTable"], function() {
                let table = layui.table;
                let form = layui.form;
                let $ = layui.$;
                let common = layui.common;
                let util = layui.util;
                
				// 表头参数
				let cols = [
					{
					// 	type: "checkbox",
					// 	align: "center"
					// },{
					// 	title: "主键",align: "center",
					// 	field: "id",
					// 	sort: true,
					// },{
						title: "语言代码",align: "center",
						field: "code",
					},{
						title: "语种",align: "center",
						field: "name",
                    },{
                        title: "译文数量",align: "center",
                        field: "number",

					},{
						title: "操作",
						toolbar: "#table-bar",
						align: "center",
						fixed: "right",
						width: 220,
					}
				];
				
				// 获取表格自定义表头和列宽
				cols = layuiTableFilter(SELECT_API,cols)
				// 渲染表格
				function render()
				{
				    layuiRender({
				        url: SELECT_API,
				        cols:[cols],
				        // 表格拖拽回调  weight 是默认的排序字段 按需调整
				        // where:{field:'weight',order:'desc'},
				        // rowDrag:{done:(obj)=>{func.rowDragDoneFunc(obj,'weight')}},
				    });
				}
				render();
				
				
                // 编辑或删除行事件
                table.on("tool(data-table)", function(obj) {
                    if (obj.event === "remove") {
                        func.remove(obj);
                    } else if (obj.event === "edit") {
                        func.edit(obj);
                    }else if(obj.event === 'translate'){
                        layerOpen('语言包 - '+obj.data.name,'/admin/utils/util-lang-detail/index?lang_id='+obj.data.id,'90%','90%')
                    }
                });

                // 表格顶部工具栏事件
                table.on("toolbar(data-table)", function(obj) {
                    if (obj.event === "add") {
                        func.add();
                    } else if (obj.event === "refresh") {
                        refreshTable();
                    } else if (obj.event === "batchRemove") {
                        func.batchRemove(obj);
                    } else if(obj.event === 'generate'){
                        $.post('generate',function(res){
                            layer.msg(res.msg,{icon:1});
                        })
                    }
                });

                // 表格顶部搜索事件
                layuiFormQuery('table-query');

                // 表格顶部搜索重置事件
                layuiFormReset('table-reset');

                // 表格排序事件
                layuiTableSort();

                // 新增 编辑 删除的方法集合
                 let func = lauiInit(PRIMARY_KEY,INSERT_URL,UPDATE_API,DELETE_API);
            })

        </script>
    </body>
</html>
